package ComparableAndComparator;

import java.util.ArrayList;
import java.util.List;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.TreeSet;

public class Ferry {
	public static void main(String[] args) {
			TreeSet<Integer> times = new TreeSet<Integer>();
			times.add(1205); // add some departure times
			times.add(1505);
			times.add(1545);
			times.add(1830);
			times.add(2010);
			times.add(2100);
			
			// Java 5 version
			TreeSet<Integer> subset = new TreeSet<Integer>();
			subset = (TreeSet)times.headSet(1600);
			System.out.println("J5 - last before 4pm is: " + subset.last());
			TreeSet<Integer> sub2 = new TreeSet<Integer>();
			sub2 = (TreeSet)times.tailSet(2000);
			System.out.println("J5 - first after 8pm is: " + sub2.first());
			
			// Java 6 version using the new lower() and higher() methods
			System.out.println("J6 - last: " + times.last());
			System.out.println("J6 - firts: " + times.first());
			System.out.println("J6 - last before 4pm is: " + times.lower(1600));
			System.out.println("J6 - first after 8pm is: " + times.higher(2000));
			
			ArrayList<Integer> input = null;
			List<Integer> output = adIntger(input);
		}
	
	static List<Integer> adIntger(List<Integer> lista){
		List<Integer> ls = new ArrayList<Integer>();
		return ls;
		
	}
}








class BackedCollections {
	public static void main(String argv[]){
		TreeMap<String, String> map = new TreeMap<String, String>();
		map.put("a", "ant"); map.put("d", "dog"); map.put("h", "horse");
		
		SortedMap<String, String> submap;
		submap = map.subMap("b", "g"); // #1 create a backed collection
		System.out.println(map + " " + submap); // #2 show contents
		map.put("b", "bat"); // #3 add to original
		submap.put("f", "fish"); // #4 add to copy
		map.put("r", "raccoon"); // #5 add to original - out of range
		// submap.put("p", "pig"); // #6 add to copy - out of range
		System.out.println(map + " " + submap); // #7 show final contents
	}
}


class Something {
	public static void main(String argv[]){
		TreeSet<String> s = new TreeSet<String>();
		TreeSet<String> subs = new TreeSet<String>();
		s.add("a"); s.add("b"); s.add("c"); s.add("d"); s.add("e");
		subs = (TreeSet)s.subSet("b", true, "d", true);
		s.add("g");
		s.pollFirst();
		s.pollFirst();
		s.add("c2");
		System.out.println(s.size() +" "+ subs.size());
	}
}


class Magellan {
	public static void main(String[] args) {
		TreeMap<String, String> myMap = new TreeMap<String, String>();
		myMap.put("a", "apple"); myMap.put("d", "date");
		myMap.put("f", "fig"); myMap.put("p", "pear");
		System.out.println("1st after mango: " + // sop 1
				myMap.higherKey("f"));
		System.out.println("1st after mango: " + // sop 2
				myMap.ceilingKey("f"));
		System.out.println("1st after mango: " + // sop 3
				myMap.floorKey("f"));
		SortedMap<String, String> sub = new TreeMap<String, String>();
		sub = myMap.tailMap("f");
		System.out.println("1st after mango: " + // sop 4
				sub.firstKey());
	 }
}


/*
 * Which of the System.out.println statements will produce the output 1st after mango: p?
(Choose all that apply.)
A. sop 1
B. sop 2
C. sop 3
Self Test Answers 657
658 Chapter 7: Generics and Collections
D. sop 4
E. None; compilation fails
F. None; an exception is thrown at runtime
Answer:
 A is correct. The ceilingKey() method's argument is inclusive. The floorKey() method
would be used to find keys before the specified key. The firstKey() method's argument is
also inclusive.
 B, C, D, E, and F are incorrect based on the above. (Objective 6.3)
 * */
